package com.joysuch.wwyt.common.controller;


import com.joysuch.wwyt.common.entity.CommonVersion;
import com.joysuch.wwyt.common.service.CommonVersionService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.enums.Status;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zr
 * @since 2021-07-29
 */
@RestController
@RequestMapping("/common/common-version")
@Api(tags = "版本号测试")
public class CommonVersionController {

    @Autowired
    private CommonVersionService commonVersionService;

    @ApiOperation("得到最新版本信息")
    @GetMapping("/getNew")
    public ResultBean getNew(String applicationType){
        CommonVersion finalVersion = commonVersionService.findLatestVersion(applicationType);
        return ResultBean.success(finalVersion);
    }

    @ApiOperation("新增一条版本信息")
    @PostMapping("/add")
    public ResultBean add(@RequestBody CommonVersion version){
        boolean result = commonVersionService.save(version);
        if (result){
            return ResultBean.success(Status.SUCCESS.getCode(),Status.SUCCESS.getMsg());
        }
        return ResultBean.fail(Status.FAILED.getCode(),Status.FAILED.getMsg());
    }
}

